package com.nxzh.de.executor.service.impl;

import com.nxzh.de.executor.common.utils.MyUtil;
import com.nxzh.de.executor.domain.Mode;
import com.nxzh.de.executor.domain.PreventSuckBackLog;
import com.nxzh.de.executor.mapper.suckback.MaterialEndMapper;
import com.xxl.job.core.context.XxlJobHelper;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author : lcg
 * @version : v1.0
 * @className : PowerAndPotPositionServiceImpl
 * @description :
 * @createTime : 2023/4/2 10:00
 */
@Service("DescendingCrucibleServiceImpl")
@Scope("prototype")
@Slf4j
public class SuckBackServiceImpl {

    private static final Logger logger = LoggerFactory.getLogger(SuckBackServiceImpl.class);

    @Resource(name = "MaterialEndMapper")
    private MaterialEndMapper materialEndMapper;

    @Resource
    private ReadInstructionsImpl readInstructions;

    public void preventHearthDX(String modelName, String deviceids) {
        logger.info("炉台防倒吸炉压波动数字化监控模型开启");
        List<Mode> modes = materialEndMapper.queryAllMode();
        List<HashMap<String, String>> crystalMode7Map = readInstructions.selectIntefaceDatas(deviceids, modes);
        ArrayList<PreventSuckBackLog> pushList = new ArrayList<>();
        if (crystalMode7Map.size() > 0) {
            logger.info("符合逻辑条数:{}", crystalMode7Map.size());
            for (HashMap<String, String> hashMap : crystalMode7Map) {
                String lotNo = hashMap.get("lot_no");
                // insert
                PreventSuckBackLog preventSuckBackLog = new PreventSuckBackLog();
                preventSuckBackLog.setDeviceId(hashMap.get("device_id"));
                if (null != lotNo && lotNo.length() > 6) {
                    preventSuckBackLog.setSeries(lotNo.substring(4, 5));
                }
                preventSuckBackLog.setLotNo(lotNo);
                preventSuckBackLog.setMode(hashMap.get("mode"));
                preventSuckBackLog.setModeName(hashMap.get("mode_name"));
                preventSuckBackLog.setRealityTorr(hashMap.get("zsyl"));
//                preventSuckBackLog.setStandardTorr(hashMap.get("sdyl"));
                preventSuckBackLog.setOffsetTorr(hashMap.get("offset"));
                preventSuckBackLog.setLotGroup(hashMap.get("lot_group"));
                preventSuckBackLog.setSubValue(hashMap.get("sub"));
                // 先不推,仅留存数据
                preventSuckBackLog.setSendFlag("0");
                preventSuckBackLog.setPerson("无");
//                preventSuckBackLog.setBdStatus(hashMap.get("dbzt"));
                preventSuckBackLog.setFbqfStatus(hashMap.get("fbqf_status"));
                preventSuckBackLog.setLotNoTime(hashMap.get("lot_no_time"));
                preventSuckBackLog.setRunTime(hashMap.get("run_time"));
                preventSuckBackLog.setCreateTime(MyUtil.getNowTime());
                preventSuckBackLog.setPreviousData(hashMap.get("previous_data"));
                preventSuckBackLog.setKcfStatus(hashMap.get("kcf_status"));
                pushList.add(preventSuckBackLog);
                // 记录推送标识 push   人、系列、数据、时间间隔  指定间隔时间查询判断
            }
            materialEndMapper.batchInsertModelLog(pushList);
        } else {
            XxlJobHelper.log("暂无炉压异常数据");
            logger.info("暂无炉压异常数据");
        }
    }

}
